package com.aikon.wht.jmx;

import java.lang.management.ManagementFactory;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

/**
 * JMX practice.
 * 
 * @author haitao.wang
 *
 */
public class TestOfJmx implements DynamicMBean{

	public static void main(String[] args) throws MalformedObjectNameException, InstanceAlreadyExistsException,
			NotCompliantMBeanException, InstanceNotFoundException, ReflectionException, MBeanException {

		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

		ObjectName objName = new ObjectName("com.pukka.hymc.jmx:name=JmxServiceImplMBean");

		JmxServiceMBean JmxServiceImplMBean = new JmxServiceImplMBean();

		mbs.registerMBean(JmxServiceImplMBean, objName);

		mbs.invoke(objName, "print", new Object[] { "haitao.wang" }, new String[] { "java.lang.String" });
	}
	
	public void print(){
		System.out.println("asdf");
	}

	public Object getAttribute(String attribute)
			throws AttributeNotFoundException, MBeanException, ReflectionException {
		// TODO Auto-generated method stub
		return null;
	}

	public void setAttribute(Attribute attribute)
			throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
		// TODO Auto-generated method stub
		
	}

	public AttributeList getAttributes(String[] attributes) {
		// TODO Auto-generated method stub
		return null;
	}

	public AttributeList setAttributes(AttributeList attributes) {
		// TODO Auto-generated method stub
		return null;
	}

	public Object invoke(String actionName, Object[] params, String[] signature)
			throws MBeanException, ReflectionException {
		// TODO Auto-generated method stub
		return null;
	}

	public MBeanInfo getMBeanInfo() {
		// TODO Auto-generated method stub
		return new MBeanInfo(null, null, null, null, null, null);
	}
}
